package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Role;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/10/16
 * @description
 */
@RestController
@RequestMapping("role")
public class RoleController {

    @Value("${server.port}")
    private String port;

    @RequestMapping("m1")
    public String method1(HttpServletRequest request){
        String color = request.getParameter("color");
        return  " roleController method1  ok port =  "+port+"color = "+color;
    }

    // http://localhost:8544/role/m2?id=1
    @GetMapping("m2")
    public String method2(Integer id){
        return  " roleController method2  ok port =  "+port +"id="+id;
    }

    @GetMapping("m3/{id}")
    public String method3(@PathVariable Integer id){
        return  " roleController method3  ok port =  "+port +"id="+id;
    }

    // http://localhost:8544/role/m4?id=1&roleName=root&description=管理员
    @GetMapping("m4")
    public String method4(Role role){
        System.out.println("role = " + role);
        return  " roleController method3  ok port =  "+port;
    }

    @PostMapping("m5")
    public String method5(@RequestBody Role role){
        System.out.println("role = " + role);
        return  " roleController method3  ok port =  "+port;
    }


    @PostMapping("m6")
    public String method6(@RequestBody List<Integer> ids){
         System.out.println("ids = " + ids);
         return  " roleController method3  ok port =  "+port;
    }

    @PostMapping("m7")
    public Role method7(){

        Role role = new Role();
        role.setRoleName("root");
        role.setId(1);
        role.setDescription("这是一个管理员");

        return role;

    }

    @PostMapping("m8")
    public List<Role> method8(){

        Role role = new Role();
        role.setRoleName("root");
        role.setId(1);
        role.setDescription("这是一个管理员");


        List<Role> list = Arrays.asList(role, role, role);
        return  list;
    }
}
